<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  
</head>
<body>
  <div id="app">
    
    {{ num }}
    <hr>
    {{  doubleNum }}
    <button @click="setDoubleNum">修改计算属性</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        num: 10
      },
      methods: {
        setDoubleNum(){
          this.doubleNum = 100
        }
      },
      computed: {
        doubleNum: {
          get(){
            // getter
            return this.num*2
          },
          set(newVal){
            // setter
            console.log('setter触发了',newVal);
            this.num = newVal / 2;
          }
        }
      }
    })

  
  
  </script>
</body>
</html>